﻿@model TrialManagmentTool.Models.TrialBasicSummaryViewModel
@{
    ViewBag.Title = "添加示范点";
    Layout = "~/Views/Shared/Layout.Mobile.cshtml";
}
<style>
    .list-block li {
        position: relative !important;
    }
</style>
<div class="page-group">
    <div class="page  page-current" id="BasicInfo">
        <div class="content">
            <div class="list-block">
                <ul>
                    <!-- Text inputs -->
                    <li id="maindata1">
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-city"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">@Model.dataList[0].ChineseDesc<span class="mark">&nbsp;&nbsp;*</span></div>
                                <div class="item-input">
                                    <input type="text" id="cityname" value="@Model.dataList[0].value" maxlength="200" placeholder="请输入" />
                                </div>
                            </div>
                        </div>
                    </li>
                    <li id="maindata2">
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-coorpate"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">@Model.dataList[1].ChineseDesc</div>
                                <div class="item-input">
                                    <input type="text" id="coorpate" value="@Model.dataList[1].value" maxlength="50" placeholder="请输入">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li id="maindata3">
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-zacao"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">@Model.dataList[2].ChineseDesc<span class="mark">&nbsp;&nbsp;*</span></div>
                                <div class="item-input">
                                    <input type="text" id="pinzhong" value="@Model.dataList[2].value" maxlength="50" placeholder="请输入">
                                </div>
                            </div>
                        </div>
                    </li>

                    <li id="maindata4">
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-pinzhong"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">@Model.dataList[3].ChineseDesc<span class="mark">&nbsp;&nbsp;*</span></div>
                                <div class="item-input">
                                    <input type="text" id="zaipei" value="@Model.dataList[3].value" maxlength="50" placeholder="请输入">
                                </div>
                            </div>
                        </div>
                    </li>

                    <li id="maindata5">
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-season"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">@Model.dataList[4].ChineseDesc<span class="mark">&nbsp;&nbsp;*</span></div>
                                <div class="item-input">
                                    <input type="text" id="zacao" value="@Model.dataList[4].value" maxlength="50" placeholder="请输入">
                                </div>
                            </div>
                        </div>
                    </li>

                    <li id="maindata6">
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-fengbi"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">@Model.dataList[5].ChineseDesc<span class="mark">&nbsp;&nbsp;*</span></div>
                                <div class="item-input">
                                    <label class="label-switch">
                                        <input type="checkbox" id="fengbi" data-need=@Model.dataList[5].isMandary onchange="UpdateCheckboxDesc(this)">
                                        <div class="checkbox"><span id="fengbichkdesc" style="margin-left:60px"></span></div>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </li>

                    <li id="maindata7">
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-zaipei"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">@Model.dataList[6].ChineseDesc</div>
                                <div class="item-input">
                                    <input type="text" id="season" value="@Model.dataList[6].value" maxlength="50" placeholder="请输入">
                                </div>
                            </div>
                        </div>
                    </li>



                </ul>
            </div>
            <div class="content-block">
                <div class="row">
                    <a href="#" id="SaveBasic" class="button button-success button-big button-fill">保存</a>
                </div>
            </div>
        </div>
        <div style="position:absolute;right:0;top:100px">
            <a class="filterArea" onclick="loadPage()"> <img src="@TrialManagementTool.Helper.UrlHelper.alterContent("Images/fangan.png")" class="fangan" />  </a>
        </div>
    </div>
    <div class="page" id="purpose">
        <header class="bar bar-nav">
            <a class="button button-link button-nav pull-left back">
                <span class="icon icon-left"></span>
                返回
            </a>
            <h1 class='title'>示例方案</h1>
        </header>
        <div class="content" style="width:90%">

            @{var data = new ViewDataDictionary();

            data.Add("TrialGuideID", Model.TrialGuideID);
            Html.RenderPartial("Purpose", null, data); }
        </div>
    </div>
</div>

@for (int i = 0; i < Model.dataList.Count(); i++)
{
    if (Model.dataList[i].display == false)
    {
        <script>
            $("#maindata" + (@i+1)).css("display", 'none');
        </script>
    }
}
@if (Model.dataList[5].value == "1")
{
    <script>
        $("#fengbi").attr("checked", "true");
        $("#fengbichkdesc").html("是");
    </script>
}
else
{
    <script>
        $("#fengbichkdesc").html("否");
    </script>
}

<script>
    var allowsubmit = true;
    $("#SaveBasic").on("click", function () {
        if ($("#cityname").val().length <= 0 && $("#maindata1").css('display') != "none") {
            $.toast("请先输入市县/乡镇");
            //} else if ($("#coorpate").val().length <= 0 && $("#maindata2").css('display') != "none") {
            //    $.toast("请先输入合作单位");
        } else if ($("#pinzhong").val().length <= 0 && $("#maindata3").css('display') != "none") {
            $.toast("请先输入作物品种");
        } else if ($("#zaipei").val().length <= 0 && $("#maindata4").css('display') != "none") {
            $.toast("请先输入" + '@Model.dataList[3].ChineseDesc');
        } else if ($("#zacao").val().length <= 0 && $("#maindata5").css('display') != "none") {
            $.toast("请先输入" + '@Model.dataList[4].ChineseDesc');
        } else {
            $.confirm('是否确认保存?保存后不可修改.',
       function () {
           if (allowsubmit == true) {
               allowsubmit = false;
               var postdata = { basicInfo: {}, ID: {} }
               postdata.basicInfo.Address = $("#cityname").val();
               postdata.basicInfo.Partner = $("#coorpate").val();
               postdata.basicInfo.CropCategory = $("#pinzhong").val();
               postdata.basicInfo.SubCropCategory = $("#season").val();
               postdata.basicInfo.Object = $("#zacao").val();
               postdata.basicInfo.SeedMode = $("#zaipei").val();
               if ($("#maindata6").css("display") != "none") {
                   postdata.basicInfo.IsClosed = $("#fengbi").is(':checked');
               }
               postdata.ID =@Model.ID
               $.ajax({
                   url: fixUrl("api/Trial/AddTrialBasicInfo"),
                   data: postdata,
                   type: "post",
                   success: function (data) {
                       $.toast("提交成功，跳转中。。。");
                       setTimeout(function () {
                           location.href = fixUrl("TrialMobile/ReportManagement?id=" + data);
                       })
                   },
                   error: function (data) {
                       allowsubmit = true;
                       if (data.status == "401") {
                           $.alert('登录超时');
                       } else {
                           $.alert('保存失败,请重试');
                       }
                   }
               })
           }
       },
       function () {
           //$.alert('You clicked Cancel button');
       }
     )

        }
    })

    function loadPage() {
        $.router.load("#purpose");
        init();
    }

    function UpdateCheckboxDesc(target) {
        if ($("#" + target.id).is(':checked') == true) {
            $("#fengbichkdesc").html("是");
        } else {
            $("#fengbichkdesc").html("否");
        }
    }
</script>